Video encoding using variable bit rates

ABSTRACT

A system and method is provided for variable bit rate encoding using a complexity ratio. Quantization parameter is calculated using a complexity ratio, which is equal to a local complexity divided by a global complexity. Complex pictures are allocated a larger bit budget relative to simple pictures. With the larger bit budget the quality of complex pictures can be maintained while reducing the overall size of the encoded video stream.

BACKGROUND OF THE INVENTION

1. Field of the Invention

The present invention relates to digital video encoding. Morespecifically, the present invention relates to methods of video encodingusing variable bit rate to improve the video quality of an encoded videostream.

2. Discussion of Related Art

Due to the advancement of semiconductor processing technology,integrated circuits (ICs) have greatly increased in functionality andcomplexity. With increasing processing and memory capabilities, manyformerly analog tasks are being performed digitally. For example,images, audio and even full motion video can now be produced,distributed, and used in digital formats.

FIG. 1( a) is an illustrative diagram of a digital video stream 100.Digital video stream 100 comprises a series of individual digital images100_0 to 100_N, each digital image of a video stream is often called aframe. For full motion video a video frame rate of 30 images per secondis desired. As illustrated in FIG. 1( b), a digital image 100_Zcomprises a plurality of picture elements (pixels). Specifically,digital image 100_Z comprises Y rows of X pixels. For clarity, pixels ina digital image are identified using a 2-dimensional coordinate system.As shown in FIG. 1( b), pixel P(0,0) is in the top left corner ofdigital image 100_Z. Pixel P(X-1,0) is in the top right corner ofdigital image 100_Z. Pixel P(0,Y-1) is in the bottom left corner andpixel P(X-1, Y-1) is in the bottom right corner. Typical image sizes fordigital video streams include 720×480, 640×480, 320×240 and 160×120.

FIG. 2 shows a typical digital video system 200, which includes a videocapture device 210, a video encoder 220, a video channel 225, a videodecoder 230, a video display 240, and an optional video storage system250. Video capture device 210, typically a video camera, provides avideo stream to video encoder 220. Video encoder 220 digitizes andencodes the video stream and sends the encoded digital video stream overchannel 225 to video decoder 230. Video decoder 230 decodes the encodedvideo stream from channel 225 and displays the video images on videodisplay 240. Channel 225 could be for example, a local area network, theinternet, telephone lines with modems, or any other communicationconnections. Video decoder 230 could also receive a video data streamfrom video storage system 250. Video storage system 250 can be forexample, a video compact disk system, a hard disk storing video data, ora digital video disk system. The video stream from video storage system250 could have been previously generated using a video capture deviceand a video encoder. However, some video streams may be artificiallygenerated using computer systems.

A major problem with digital video system 200 is that channel 225 istypically limited in bandwidth. As explained above a full-motion digitalvideo stream can comprise 30 images a second. Using an image size of640×480, a full motion video stream would have 18.4 million pixels persecond. In a full color video stream each pixel comprises three bytes ofcolor data. Thus, a full motion video stream would require a transferrate in excess of 52 megabytes a second over channel 225. For internetapplication most users can only support a bandwidth of approximately 56Kilobits per second. Thus, to facilitate digital video over computernetworks, such as the internet, digital video streams must becompressed.

Most video compression algorithms, such as MPEG2 and MPEG4, reduce thebandwidth requirement of a digital video stream by not sending redundantinformation across channel 225. For example, as shown in FIG. 3, adigital video stream includes digital image 301 and 302. Digital image301 includes a video object 310_1 and video object 340_1 on a blankbackground. Digital image 302 includes a video object 310_2, which isthe same as video object 310_1, and a video object 340_2, which is thesame as video object 340_1. Rather then sending data for all the pixelsof digital image 301 and digital image 302, a digital video stream couldbe encoded to simply send the information that video object 310_1 fromdigital image 301 has moved three pixels to the left and two pixels downand that video object 340_1 from digital image 301 has moved one pixeldown and four pixels to the left. Thus rather than sending all thepixels of image 302 across channel 225, video encoder 220 can senddigital image 301 and the movement information, usually encoded as a twodimensional motion vector, regarding the objects in digital image 301 tovideo decoder 230. Video decoder 230 can then generate digital image 302using digital image 301 and the motion vectors supplied by video encoder220. Similarly, additional digital images in the digital video streamcontaining digital images 301 and 302 can be generated from additionalmotion vectors.

However, most full motion video streams do not contain simple objectssuch as video objects 310_1 and 340_1. Object recognition in real lifeimages is a very complicated and time-consuming process. Thus, motionvectors based on video objects are not really suitable for encodingdigital video data streams. However, it is possible to use motion vectorencoding with artificial video objects. Rather than finding distinctobjects in a digital image, the digital image is divided into aplurality of macroblocks. A macroblock is a number of adjacent pixelswith a predetermined shape and size. Typically, a rectangular shape isused so that a rectangular digital image can be divided into an integernumber of macroblocks. FIG. 4 illustrates a digital image 410 that isdivided into a plurality of square macroblocks. For clarity, macroblocksare identified using a 2-dimensional coordinate system. As shown in FIG.4, macroblock MB(0,0) is in the top left corner of digital image 410.Macroblock MB(X-1,0) is in the top right corner of digital image 410.Macroblock MB(0,Y-1) is in the bottom left corner and macroblock MB(X-1,Y-1) is in the bottom right corner. Calculations of motion vectors iswell known in the art and not an integral part of the present invention.Congratulation.

In general frames produced using motion estimation using only precedingframes are called Predicted Frames (P Frames). Frames produced usingmotion estimation using both preceding and succeeding frames are calledbi-directional (B Frames). Frames that do not use information frompreceding or succeeding frames are called Intra frames (I Frames). Interms of data size, intra frames require more data than predictedframes, which require more data than bi-directional frames. However, thequality of each succeeding image calculated using motion estimationdegrades. Thus, an encoded video stream are typically arranged asmultiple groups of pictures (GOPs). Each group of pictures can bedecoded without reference to another group of picture. Thus each groupof pictures starts with an intra frames and may include additional intraframes spaced periodically throughout the group of pictures to maintainpicture quality.

FIG. 6 is a simplified block diagram of a typical video encoder 600.Video encoder 600 includes a motion estimation unit 610, a discretecosine transformation unit 620, quantizer 630, and a run-length coder640. Motion estimation unit 610 performs motion estimation on in inputvideo stream I_VS to generate predicted frames and bi-directionalframes. Motion estimation unit 610 typically includes an embeddeddecoder to insure that the encoding can be properly decoded. Discretecosine transformation unit 620 transform each frame into the frequencydomain which provides more efficient data storage for video streams.Quantizer 630 reduces the magnitude of the transform coefficients ofeach frame to reduce the amount a data required for each frame. Thequantization step is a “lossy” operation in that the original frameinformation can not be reproduced from the quantized transformcoefficients. The amount of quantization can be controlled by adjustinga frame quantization parameter F_MQUANT. The quantized coefficients arethen run-length encoded to form an encoded video stream E_VS. The sizeand therefore the bit rate of encoded video stream E_VS can becontrolled using frame quantization parameter F_MQUANT.

As explained above video compression is generally needed because channel225 (FIG. 2) has limited bandwidth. Thus some video encoders use aconstant bit rate (CBR) scheme so that the encoded video stream can betransferred across channel 225. However, constant bit rate compressiongenerally causes varying picture quality especially when comparing acomplex picture with a simple picture or during scene changes, whichwould not have the benefits of motion estimation. Another approach is touse a variable bit rate and buffering to fully utilize channel 225. Theaverage of the variable bit rate over time must be close to a target bitrate that channel 225 can handle. Using variable bit rate, more bitsthat are not necessary for simple pictures to achieve a desired picturequality can be saved for use on complex pictures. Thus, in theory theoverall picture quality of the encoded video stream can be improvedusing variable bit rate encoding. However, allocating the bits to eachframe to achieve the desired picture quality level can be very complex.Hence there is a need for a method or system to control the framequantization parameter to allocate bits to the frames of a video streamto achieve high picture quality.

SUMMARY

Accordingly, the present invention provides a method and system forencoding a digital video stream providing higher picture quality withoutincreasing computational overhead. Specifically, the present inventionallocates and uses more bits to encode complex pictures than for simplepictures. By increasing the number of bits used to encode complexpictures, the quality of the complex pictures are improved. Becausesimple pictures are less complex, the reduction in the number of bitsused for encoding the simple pictures does not result is perceivableloss of picture quality. The number of bits used to encode a frame isrelated to a frame quantization parameter, which controls thequantization of the frame. The present invention uses the complexity ofthe frame to determine the frame quantization parameter.

In accordance with one embodiment of the present invention, a framecomplexity calculation unit calculates a complexity ratio for thecurrent frame. The complexity ratio is equal to a local complexitydivided by a global complexity. A current frame bit rate calculationunit uses the complexity ratio to calculate a current frame bit rate,which limits the number of bits used to encode the current frame. Acurrent frame MQUANT calculation unit calculates the frame quantizationparameter from the current frame bit rate.

Some embodiments of the present invention also include a bit balanceadjustment unit, which calculates a bit balance adjustment values forthe current frame bit rate calculation unit. The bit balance adjustmentfactor is indicative of the number of bits available or the number ofbits that need to be saved due to the encoding of previous frames.Furthermore, some embodiments of the present invention include a framecoding efficiency calculation unit, which calculates a frame codingefficiency factor for current frame MQUANT calculation unit. The framecoding efficiency factor is dependent on the frame type of the currentframe is used to tailor the frame quantization parameter for the frametype.

The present invention will be fully understood in view of the followingdescription and drawings.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1( a) is an illustration of a digital video stream of digitalimages.

FIG. 1( b) is a diagram of a digital image comprising picture elements(pixels).

FIG. 2 is a block diagram of a digital video system.

FIG. 3 is an illustration of object encoding of a digital video stream.

FIG. 4. is a diagram of a digital image divided into macroblocks.

FIGS. 5( a)-5(b) are an illustration of typical macroblocks.

FIG. 6 is a simplified block diagram of a video encoder.

FIG. 7 is a block diagram quantization parameter calculation unit.

FIG. 8 is a block diagram of a bit balance adjustment unit.

FIG. 9 is a block diagram of a macroblock level MQUANT adjustment unit.

DETAILED DESCRIPTION

As explained above, video encoders using variable bit rate can producean encoded video stream with higher overall picture quality than usingconstant bit rate. However, to achieve the higher picture quality theavailable bits must be allocated to the frames in an intelligent manner.Depending on the channel and decoder to be used with the encoded videostream, certain constraints on the variable bit rate are present.Specifically, a burst bit rate BURST_RATE is the maximum bit rate thatthe channel can accept data and a target bit rate TARGET_RATE is therate that the average variable bit rate should equal. For conveniencethese bit rates are converted to a per frame bit rate. Specifically, aframe burst bit rate F_BURST_RATE is equal to the burst bit rateBURST_RATE divided by a frame rate F_RATE of the video stream (i.e.F_BURST_RATE=BURST_RATE/F_RATE). Similarly, a frame target bit rateF_T_RATE is equal to the target bit rate TARGET_RATE divided by framerate F_RATE of the video stream (i.e. F_T_RATE=TARGET_RATE/F_RATE).

Another consideration is that encoded video stream E_VS is to be decodedby a video decoder. The video decoder uses a video buffer of limitedsize. While encoding encoded video stream E_VS, the video encoder mustinsure that the video buffer of the decoder will not overflow orunderflow during decoding. Therefore, most embodiments of a videoencoder includes a video buffer verifier which simulates the videobuffer of a decoder that would be used to decode encoded video streamE_VS. Video buffer verifiers are well known in the art and not anintegral part of the present invention.

The video encoder can also be configured with operational parameters forbetter control of the compression. For example, some embodiment of thepresent invention configures the video encoder with a frame maximum bitrate F_MAX_RATE and a frame minimum bit rate F_MIN_RATE. Frame maximumbit rate F_MAX_RATE, which should be less than or equal to frame burstrate F_BURST_RATE, is the maximum number of bits the encoder will use ona particular frame. The number of bits used in a frame should be cappedso that enough bits remain for later frames. Frame minimum bit rateF_MIN_RATE is the minimum number of bits the encoder should use on aparticular frame. Frame minimum bit rate F_MIN_RATE prevents the qualityof a frame from being too low. However, for some very simple frames,which require very few bits for encoding, frame minimum bit rateF_MIN_RATE can be ignored. In one embodiment of the present invention,frame maximum bit rate F_MAX_RATE is equal to the lesser of frame burstbit rate F_BURST_RATE or three times frame target bit rate F_T_RATE, andframe minimum bit rate F_MIN_RATE is equal to frame target rate F_T_RATEdivided by 2.

FIG. 7 is a block diagram of a frame quantization parameter calculationunit 700. Frame quantization parameter calculation unit 700, whichincludes a bit balance adjustment unit 710, a current frame complexitycalculation unit 720, a current frame bit rate calculation unit 730, acurrent frame coding efficiency calculation unit 740, and a currentframe MQUANT calculation unit 750, calculates frame quantizationparameter F_MQUANT for a current frame. Bit balance adjustment unit 710tracks the number of bits that have been used in previous frames todetermine a bit balance adjustment value BIT_BAL_ADJ for the currentframe. Frame complexity calculation unit 720 calculates picturecomplexity for the current frame (i.e. local complexity) as well astracking the picture complexity of previous frames (i.e. globalcomplexity). Frame complexity calculation unit 720 provides a complexityratio C_RATIO, which is the ratio of the local complexity to the globalcomplexity, to current frame bit rate calculation unit 730. Currentframe bit rate calculation unit 730 uses complexity ratio C_RATIO andbit balance adjustment value BIT_BAL_ADJ to calculate the current framebit rate C_F_RATE, which is provided to current frame MQUANT calculationunit 750 and bit balance adjustment unit 710. Current frame MQUANTcalculation unit 750 converts current frame bit rate C_F_RATE into framequantization parameter F_MQUANT based on the coding efficiency for eachframe type (i.e. intra frame, predicted frame, bi-directional frame),provided by coding efficiency calculation unit 740. Specifically, framecoding efficiency calculation unit provides frame coding efficiencyfactors F_CE[x] for intra frames, predicted frames and bi-directionalframes to current frame MQUANT calculation unit 750.

FIG. 8 is a block diagram of one embodiment of bit balance adjustmentunit 710, which includes a bit balance register 810, a bit balanceadjustment register 820, a divider 830, a duration table 840, and anadder/subtractor 850. Bit balance register 810 stores a bit balanceBIT_BAL, which indicates whether the previously processed frames haveused more or less bits allotted by the frame target bit rate F_T_RATE. Apositive bit balance BIT_BAL indicates that the previously processedframes have on average used less than frame target bit rate F_T_RATEbits per frame. Thus, additional bits may be used to process the currentor later frames. Conversely, a negative bit balance BIT_BALL indicatesthat the previously processed frames have on average used more thanframe target bit rate F_TARGET RATE bits per frame. Thus, the currentand future frames should use less bits to bring bit balance BIT_BALLback to zero. Bit Balance register 810 is updated after each frame isprocessed specifically, adder/subtractor 850 adds frame target bit rateF_T_RATE to bit balance BIT_BAL and subtracts a current frame bit rateC_F_RATE (from current frame bit rate calculation unit 730, see FIG. 7),which is equal to the number of bits used to encode the current frame.The result from adder/subtractor 850 is stored in bit balance register810.

While bit balance BIT_BAL indicates the number of extra bits availableor the number of excess bits previously used, bit balance BIT_BAL istypically not restored in a single frame. Bit balance adjustmentregister 820 provides a bit balance adjustment factor BIT_BAL_ADJ thatis used by current frame bit rate calculation unit 730 (FIG. 7).Duration table 840 provides a duration value DURATION to divider 830,which divides bit balance BIT_BAL by duration value DURATION. Thequotient from divider 830 is stored in bit balance adjustment register820. Duration value DURATION depends on bit balance BIT_BAL and thevideo buffer size. Duration value DURATION corresponds to roughly thenumber of frames before bit balance BIT_BAL returns to zero. To try andkeep bit balance BIG_BAL close to zero, duration value DURATIONincreases when bit balance BIT_BAL decreases and duration value DURATIONdecreases when bit balance BIT_BAL increases. In one embodiment of thepresent invention, duration value DURATION is equal to 512 when bitbalance BIT_BAL is less than the video buffer size, is equal to 484 whenbit balance BIT_BAL is greater than or equal to the video buffer sizeand less than two times the video buffer size, and is equal to 256 whenbit balance BIT_BAL is greater than or equal to two times the videobuffer size.

In general the number of bits required to obtain a given picture qualityfor a frame is proportional to the complexity of the frame. Framecomplexity is intrinsic to the frame itself and is not dependent on themethod of encoding. Frame complexity calculation unit 720 (FIG. 7)calculates a local complexity LOCAL_CX, a global complexity GLOBAL_CX,and a complexity ratio C_RATIO, which is equal to local complexityLOCAL_CX divided by global complexity GLOBAL_CX. Frame complexitycalculation unit 720 provides the complexity ratio to current frame bitrate calculation unit 730. In one embodiment of the present invention,picture complexities are calculated for intra frames, predicted frames,and bi-directional frames with different constants. Equation EQ1provides a simple formula for frame complexity F_CX[x] based on anaverage frame quantization parameter AVG_MQ[x], current frame bit rateC_F_RATE, the macroblock width MB_WIDTH and the macroblock heightMB_HEIGHT of the macroblocks used for the frame. The variable “x” can beI for intra frames, P for predicted frames, and B for bi-directionalframes.F _(—) CX[x]=AVG _(—) MQ[x]*(F _(—) C_RATE/(MB_WIDTH*MB_HEIGHT))>As used herein, “G>>H” means to right shift the value G by H bits, whichis equivalent to integer division by 2 to the power of H. Average framequantization parameter AVG_MQ[x] is the average quantization parameterused to process frames of each type. Initially average framequantization parameter AVG_MQ[x] is initialized to be equal to aquantization parameter constant MQ_C[x] multiplied by macroblock widthMB_WIDTH and macroblock height MB_HEIGHT and divided by frame target bitrate F_T_RATE. Equation EQ2 shows symbolically how to calculate averageframe quantization parameter AVG_MQ[x].AVG _(—) MQ[x]=MQ _(—) C[x]*(MB_WIDTH*MB_HEIGHT)/F _(—) T_RATE  (EQ2)From empirical evidence and simulation results, quantization parameterconstant MQ_C[I] of intra frames should be smaller than quantizationparameter constant MQ_C[P] for predicted frames. Quantization parameterconstant MQ_C[B] for bi-directional frames should be larger thanquantization parameter constant MQ_C[P] for predicted frames. In aparticular embodiment of the present invention quantization parameterconstant MQ_C[x] is equal to 500 for intra frames, 500 for predictedframes, and 700 for bi-directional frames.

In one embodiment of the present invention, frame complexity calculationunit 720 calculates a new average local complexity N_A_L_CX, as anintermediary to calculate local complexity LOCAL_CX. New average localcomplexity N_A_L_CX is equal to a weighted average of the framecomplexities weighted by frame types (i.e. intra frames, predictedframes, and bi-directional frames). Specifically, new average localcomplexity N_A_L_CX is equal to the sum of the number of intra frames inthe current group of pictures times the intra frame complexity F_CX[I],the number of predicted frames in the current group of pictures timespredicted frame complexity F_CX[P], and the number of bi-directionalframes in the current group of pictures times the bi-directional framecomplexity F_CX[B] divided by the total number of frames in the currentgroup of pictures. Equation EQ3 shows symbolically how to calculate newaverage local complexity N_A_L_CX.N _(—) A _(—) L _(—) CX=(N _(—) I*F _(—) CX[I]+N _(—) P*F _(—) CX[P]+N_(—) B*F _(—) CX[B])/N  (EQ3)Where the N_I, N_P and N_B is the number of I, P and B frames in thecurrent group of pictures, respectively, and N is the number of framesof the current group of pictures that have been processed. To avoidlarge fluctuations in local complexity LOCAL_CX, new values of localcomplexity LOCAL_CX are calculated as a weighted average of the currentvalue of local complexity LOCAL_CX and new average local complexityN_A_L_CX. The initial value of local complexity LOCAL_CX is set equal toinitial intra frame complexity F_CX[I]. In a specific embodiment of thepresent invention, a new value for local complexity LOCAL_CX is equal tonew average local complexity N_A_L_CX plus three times the current valueof local complexity LOCAL_CX divided by 4. Equation EQ4 showssymbolically how to calculate a new value for local complexity LOCAL_CX.LOCAL_(—) CX=(N _(—) A _(—) L _(—) CX+3*LOCAL_(—) CX)/4  (EQ4)

Global complexity GLOBAL_CX is the long term average of local complexityLOCAL_CX. In one embodiment of the present invention, global complexityGLOBAL_CX is updated every 16 frames in the current group of pictures.When global complexity GLOBAL_CX is updated, a new value for globalcomplexity GLOBAL_CX is equal to a global complexity coefficient GGCtimes local complexity LOCAL_CX plus the current value of globalcomplexity GLOBAL_CX times one minus global complexity coefficient GGC.Equation EQ5 shows symbolically how to calculate a new value for globalcomplexity GLOBAL_CX.GLOBAL_(—) CX=G _(—) C*LOCAL_(—) CX+(1−G _(—) C)*GLOBAL_(—) CX  (EQ5)Near the beginning of a group of pictures, local complexity LOCAL_CX ismore significant to global complexity GLOBAL_CX, therefore globalcomplexity coefficient GCC should be greater for early frames andsmaller for later frames in a group of pictures. In one embodiment ofthe present invention global complexity coefficient is equal to 1/32when the number of encoded frames is less than 2000 and is equal to1/512 otherwise. The initial value of global complexity GLOBAL_CX is setequal to the initial value local complexity LOCAL_CX. As stated above,complexity ratio C_RATIO is equal to local complexity LOCAL_CX dividedby global complexity GLOBAL_CX. Equation EQ6 shows symbolically how tocalculate complexity ratio C_RATIO.C_RATIO=LOCAL_(—) CX/GLOBAL_(—) CX  (EQ6)Complexity ratio C_RATIO is provided to current frame bit ratecalculation unit 730.

Current frame bit rate calculation unit calculates current frame bitrate C_F_RATE to be equal to bit balance adjustment value BIT_BAL_ADJplus a rate control parameter R_CTRL multiplied by complexity ratioC_RATIO multiplied by frame target rate F_T_RATE plus frame target rateF_T_RATE multiplied by the difference between one and rate controlparameter R_CTRL. Equation EQ7 shows symbolically how to calculatecurrent frame bit rate C_F_RATE.

$\begin{matrix}\begin{matrix}{{{C\_ F}{\_ RATE}} = {{{BIT\_ BAL}{\_ ADJ}} +}} \\{\left( {{R\_ CTRL}*{C\_ RATIO}*{F\_ T}{\_ RATE}} \right) +} \\{\left( {{F\_ T}{\_ RATE}*\left( {1 - {R\_ CTRL}} \right)} \right)}\end{matrix} & ({EQ3})\end{matrix}$The value of rate control parameter R_CTRL depends on the number offrames that have been encoded. In general, complexity ratio C_RATIOshould have greater impact on current frame rate C_F_RATE at thebeginning of encoding a video stream. Therefore rate control parameterR_CTRL should decrease as the number of processed frames increases. Inone embodiment of the present invention, rate control parameter R_CTRLis equal to 0.75 when less than 1000 frames have been encoded, is equalto 0.5 when between 1000 and 2000, inclusive, frames have been encoded,and is equal to 0.375 when more than 2000 frames have been encoded.Current frame bit rate C_F_RATE is also limited by frame maximum bitrate F_MAX_RATE and frame minimum bit rate F_MIN_RATE. Thus, if currentframe bit rate C_F_RATE is greater than frame maximum bit rateF_MAX_RATE, then current frame bit rate C_F_RATE is set equal to framemaximum bit rate F_MAX_RATE. Conversely, if current frame bit rateC_F_RATE is less than frame minimum bit rate F_MIN_RATE, then currentframe bit rate C_F_RATE is set equal to frame minimum bit rateF_MIN_RATE.

The coding efficiency of each frame type must be taken into account todetermine frame quantization parameter F_MQUANT from current frame bitrate C_F_RATE. Thus, frame coding efficiency calculation unit 740calculates frame coding efficiency factor F_CE[x], for each type offrame (i.e., intra frames, predicted frames, and bi-directional frames.In general frame coding efficiency factor F_CE[x] is equal to framequality constant FQC[x] divided by frame complexity F_CX[x], where x canbe I for an intra frame, P for a predicted frame, and B for abi-directional frame. In general bi-directional frames provide greatercoding efficiency than predicted frames, which provide greater codingefficiency than intra frames. Thus, frame quality constant FQC[I] isgenerally smaller than frame quality FQC[P], which is smaller than framequality constant FQC[B]. In one embodiment of the present invention,frame quality constant FQC[I] is equal to 56,000; frame quality FQC[P]is equal to 64,000; and frame quality FQC[B] is equal to 70000. In someembodiments of the present invention, dramatic changes to codingefficiency between successive frames are avoided by using a codingefficiency coefficient CEC in the range of 0 to 1, inclusive. A specificembodiment of the present invention uses 0.75 for coding efficiencycoefficient CEC. In these embodiments, a new value of frame codingefficiency factor F_CE[x] is equal to one minus coding efficientcoefficient CEC times the current value of frame coding efficiencyfactor F_CE[X] plus coding efficient coefficient times frame qualityconstant FQC[X] divided by frame complexity F_CX[X]. Equation EQ7 showssymbolically how to calculate frame coding efficiency factor F_CE[x].F _(—) CE [x]=(1−CEC)*F _(—) CE[x]+CEC*FQC[x]/F _(—) CX[x]  (EQ7)

Current frame MQUANT calculation unit 750 computes frame quantizationparameter F_MQUANT using frame coding efficiency factor F_CE[x] andcurrent frame bit rate C_F_RATE. To adjust for coding efficiency, a bitbudget BB[x] is calculated for each frame type, where x can be I forintra frame, P for predicted frame, and B for bi-directional frames. Bitbudget BB[x] is the number of bits that should be used for a frame typex. Bit budget BB[x] is equal to a bit budget coefficient BB_C timescurrent frame bit rate C_F_RATE divided by frame coding efficiencyfactor F_CE[x]. Equation EQ8 shows symbolically how to compute bitbudget BB[x].BB[x]=BB _(—) C*LOCAL_RATE/F _(—) CE[x]  (EQ8)

Determination of bit budget coefficient BB_C is based on the overall thelocal bit rates. Specifically, the total number of processed frames (N)in the current group of pictures multiplied by current frame bit rateC_F_RATE should be equal to bit budget BB[I] of intra frames multipliedby the number of intra frames (N_I) plus bit budget BB[P] of predictedframes multiplied by the number of predicted frames (N_P) plus the bitbudget BB[B] of bi-directional frames multiplied by the number ofbi-directional frames (N_B). This relationship is shown symbolically inequation EQ9.N*C _(—) F_RATE=BB[I]*N _(—) I+BB[P]*N _(—) P+BB[B]*N _(—) B  (EQ9)

Combining equations EQ8 and EQ9 and solving algebraically for bit budgetcoefficient BB_C shows that bit budget coefficient BB_C is equal to thenumber of frames (N) divided by the sum of the number of I frames (N_I)divided by frame coding efficiency factor F_CE[I] plus the number of Pframes (N_P) divided frame coding efficiency factor F_CE[P] plus thenumber of B frames (N_B) divided by frame coding efficiency factorF_CE[B]. Equation EQ10 shows symbolically how to calculate bit budgetcoefficient BB_C.BB _(—) C=N/(N _(—) I/F _(—) CE[I]+N _(—) P/F _(—) CE[P]+N _(—) B/F _(—)CE[B])  (EQ10)

By combining equation EQ10 with equation EQ8, bit budget BB[x] is shownto equal the number of Frames (N) multiplied by current frame bit rateC_F_RATE divided by the sum of the number of I frames (N_I) divided byframe coding efficiency factor F_CE[I] plus the number of P frames (N_P)divided frame coding efficiency factor F_CE[P] plus the number of Bframes (N_B) divided by frame coding efficiency factor F_CE[B]. EquationEQ11 shows symbolically how to calculate bit budget BB[x].BB[x]=N*C _(—) F_RATE/(N _(—) I/F _(—) CE[I]+N_P/F_(—) CE[P]+N _(—) B/F_(—) CE[B])/F _(—) CE[x]  (EQ11)

Bit budget BB[x] may also be modified to avoid decoding issues by thevideo buffer verifier. In the storage application, such as DVD, thevideo decoder fetches the encoded bit stream at burst bit rateBURST_RATE. If the decoder video buffer is full, the video decodersimply stops fetching the encoded bit stream automatically. Therefore,the decoder video buffer never overflows. Because video buffer verifierof the encoder models the decoder video buffer, the video bufferverifier need not be overly concerned about buffer overflows.Accordingly, in calculating frame quantization parameter F_MQUANT, videobuffer overflows problems are generally not rigorously tested. However,video buffer underflow problems are a major issue that must beprevented. To avoid underflows, a video buffer verifier fullnessVBV_FULLNESS is tracked. Specifically video buffer verifier fullnessVBV_FULLNESS is initially set equal to the video buffer size VBS. Aftera frame is processed, video buffer verifier fullness VBV_FULLNESS isupdated by adding frame burst rate F_BURST_RATE and subtracting currentframe bit usage C_F_BU, which is equal to the actual number of bits usedto encode the current frame. To avoid video buffer underflow, bit budgetBB[x] should be in the range of 40% of the video buffer size VBS to thevideo buffer verifier fullness VBV_FULLNESS. Furthermore bit budgetBB[x] is also limited by a maximum bit budget limit MAX_BB and a minimumbit budget limit MIN_BB. In one embodiment of the present inventionmaximum bit budget limit MAX_BB is equal to two times the sum of 60% ofvideo buffer verifier fullness VBV_FULLNESS plus frame target bit rateF_T_RATE and minimum bit budget limit MIN_BB is equal frame target bitrate F_T_RATE divided by four.

To avoid large fluctuation in picture quality, new values for framequantization parameter F_MQUANT are partially based on previous valuesof frame quantization parameter F_MQUANT of the same frame type.Specifically in one embodiment of the present invention framequantization parameter F_MQUANT is equal to one fourth of an averagemacroblock quantization factor of a previous frame A_MB_MQUANT_PF[x] ofthe same type as the current frame multiplied by the sum of three plusthe previous frame (of the same type) bit usage P_F_BU[x] divided by bitbudget BB[x]. As explained in more detail below, frame quantizationparameter F_MQUANT can be used for each macroblock of a frame. Howevermany encoders adjust the quantization parameter for each macroblock.Average macroblock quantization factor of a previous frameA_MB_MQUANT_PF[x] is the average of all the macroblock quantizationfactors used in a frame. Equation EQ12 shows symbolically how tocalculate frame quantization parameter F_MQUANT.F _(—) MQUANT=(A _(—) MB _(—) MQUANT _(—) PF[x]*(3+P _(—) F _(—)BU[x]/BB[x]))/4  (EQ12)

Frame quantization parameter F_MQUANT can be applied to every macroblockof the next frame. However, as illustrated in FIG. 9, some embodimentsof the present invention include a macroblock level MQUANT adjustmentunit 900 coupled to frame quantization parameter calculation unit 700.Macroblock level MQUANT adjustment unit 900 receives quantizationparameter MQUANT and generates a macroblock quantization parameterMB_MQUANT for each macroblock in the frame. The embodiment of Fig.Includes two macroblock level adjustments for the quantizationparameter. Specifically, a buffer underflow adjustment unit 910calculates an underflow adjusted quantization parameter UF_MQUANT foreach macroblock and a macroblock activity adjustment unit 920 calculatesmacroblock quantization parameter MB_MQUANT.

Buffer underflow adjustment unit provides further protection againstvideo buffer underflows. Specifically, as each macroblock is encoded,buffer underflow adjustment unit calculates a new underflow quantizationparameter UF_MQUANT for the next macroblock based on the number of bitsused to encode the current macroblock. For the first macroblock,underflow quantization parameter is set equal to frame quantizationparameter F_MQUANT.

A maximum macroblock bit budget MAX_MB_BB is calculated for themacroblocks of a frame. In one embodiment of the present inventionmaximum macroblock bit budget MAX_MB_BB is equal to the sum of videobuffer verifier fullness VBV_FULLNESS plus 10% of video buffer size VFSdivided by the product of macroblock width MB_WIDTH and macroblockheight MB_HEIGHT. Equation 13 shows symbolically how to calculatemaximum macroblock bit budget MAX_MB_BB.MAX_(—) MB _(—) BB=(VBV_FULLNESS+0.10*VBS)/(MB_WIDTH*MB_HEIGHT)  (EQ13)

The new value for underflow quantization parameter UF_MQ is equal to thecurrent value of underflow quantization parameter UF_MQ multiplied byone plus the sum of total number of bits used so far on the frame TN_BUminus the product of the number of macroblocks processed so far MB_PROCand maximum macroblock bit budget MAX_MB_BB divided by maximummacroblock bit budget MAX_MB_BB. Equation EQ14 shows symbolically how tocalculate the new value of underflow quantization parameter UF_MQ.UF _(—) MQ=UF _(—) MQ*(1+8*(TN _(—) BU−MB _(—) PROC*MB_MAX_(—)BB)/MB_MAX_(—) BB)  (EQ14)

Macroblock level MQUANT adjustment unit 900 also includes an optionalmacroblock activity adjustment unit 920, receives underflow quantizationparameter UF_MQ and calculates macroblock quantization parameterMB_MQUANT using conventional activity masking. Activity masking takesadvantage of the inability of the human eye's to perceive small changesin areas having strong edges or rapid intensity changes (i.e. areashaving a high activity level) to improve compression of macroblockshaving a high activity level. Because activity masking is well known inthe art, macroblock activity adjustment unit is not described in detail.In the embodiment of FIG. 9, macroblock activity adjustment unit onlyperforms activity masking on intra frames. Generally, macroblockactivity adjustment unit calculates an activity level for eachmacroblock. When the activity level of a macroblock is high relative tothe preceding macroblocks, macroblock quantization parameter MB_MQUANTis increased which improves the compression of the macroblock byremoving even more high frequency data, which would represent the smallchanges that would not be perceived by the human eye in the active area.Because the human eye would not perceive the small changes anyhow,removal of the small changes does not result in any perceivable imagequality reduction.

In the various embodiments of this invention, novel structures andmethods have been described to calculate a quantization parameter forvideo encoding. By using a complexity ratio to calculate thequantization parameter, complex pictures are encoded with more bits thansimple pictures. Thus, the overall picture quality of the encoded videostream is improved. The various embodiments of the structures andmethods of this invention that are described above are illustrative onlyof the principles of this invention and are not intended to limit thescope of the invention to the particular embodiments described. Forexample, in view of this disclosure, those skilled in the art can defineother macro-block formats, intra frame, predicted frames, bi-directionalframes, bit balances, complexity measures, complexity ratios, frame bitrates, quantization parameters, coding efficiencies, frame complexities,bit balance adjustment units, frame coding efficiency calculation units,frame complexity calculation units, current frame bit rate calculationunits, current frame MQUANT calculation units, duration tables, bitbalance adjustment registers, quantization parameter calculation units,buffer underflow adjustment units, macroblock activity adjustment units,encoders, decoders, and so forth, and use these alternative features tocreate a method or system according to the principles of this invention.Thus, the invention is limited only by the following claims.

1. A method of generating a frame quantization parameter for encoding acurrent frame of an incoming video stream having a plurality of frames,the method comprising: calculating a complexity ratio of the currentframe, wherein the calculating a complexity ratio of the current framecomprises: calculating a local complexity of the current frame; whereinthe calculating a local complexity of the current frame comprises:calculating a new average local complexity; and calculating a new valuefor the local complexity as a weighted average of a current value of thelocal complexity and the new average local complexity; calculating aglobal complexity of a plurality of frames; and setting the complexityratio to equal the local complexity divided by the global complexity;complexity ratio of the current frame; calculating the framequantization parameter based on the current frame bit rate.
 2. Themethod of claim 1, wherein the new average local complexity is equal toa weighted average of a plurality of frame complexities weighted by aplurality of frame types.
 3. A method of generating a frame quantizationparameter for encoding a current frame of an incoming video streamhaving a plurality of frames, the method comprising: calculating acomplexity ratio of the current frame, wherein the calculating acomplexity ratio of the current frame comprises: calculating a localcomplexity of the current frame; calculating a global complexity of aplurality of frames, wherein a new value for global complexity is equalto a global complexity coefficient times the local complexity plus acurrent value of the global complexity times one minus the globalcomplexity coefficient; and setting the complexity ratio to equal thelocal complexity divided by the global complexity; calculating a currentframe bit rate using the complexity ratio of the current frame;calculating the frame quantization parameter based on the current framebit rate.
 4. A method of generating a frame quantization parameter forencoding a current frame of an incoming video stream having a pluralityof frames, the method comprising: calculating a complexity ratio of thecurrent frame; calculating a current frame bit rate using the complexityratio of the current frame; calculating the frame quantization parameterbased on the current frame bit rate; and calculating a bit balanceadjustment factor that is used in the calculating a current frame bitrate using the complexity ratio, wherein calculating a bit balanceadjustment factor comprises: tracking a bit balance of a plurality ofpreviously processed frames; and dividing the bit balance by a durationto generate the bit balance adjustment factor.
 5. A method of generatinga frame quantization parameter for encoding a current frame of anincoming video stream having a plurality of frames, the methodcomprising: calculating a complexity ratio of the current frame;calculating a current frame bit rate using the complexity ratio of thecurrent frame; calculating the frame quantization parameter based on thecurrent frame bit rate; and calculating a bit balance adjustment factorthat is used in the calculating a current frame bit rate using thecomplexity ratio, wherein the current frame bit rate is equal to the bitbalance adjustment value plus a rate control parameter multiplied by thecomplexity ratio multiplied by a frame target rate plus the frame targetrate multiplied by the difference between one and the rate controlparameter.
 6. A method of generating a frame quantization parameter forencoding a current frame of an incoming video stream having a pluralityof frames, the method comprising: calculating a complexity ratio of thecurrent frame; calculating a current frame bit rate using the complexityratio of the current frame; calculating a frame coding efficiencyfactor; and calculating the frame quantization parameter based on thecurrent frame bit rate, wherein the calculating the frame quantizationparameter based on the current frame bit rate comprises: calculating abit budget for the current frame using the current frame bit rate;calculating an average macroblock quantization factor of a previousframe, wherein the previous frame and the current frame have a sameframe type; and calculating the frame quantization parameter using thebit budget; the average macroblock quantization factor of the previousframe, and a bit usage of the previous frame; and wherein the framequantization parameter is equal to one fourth of the average macroblockquantization factor multiplied by the sum of three plus the bit usagedivided by the bit budget.
 7. A method of generating a framequantization parameter for encoding a current frame of an incoming videostream having a plurality of frames, the method comprising: calculatinga complexity ratio of the current frame; calculating a current frame bitrate using the complexity ratio of the current frame; calculating theframe quantization parameter based on the current frame bit rate; andcalculating an underflow quantization parameter for each macroblock ofthe current frame; wherein the comprising calculating an underflowquantization parameter for each macroblock of the current framecomprises: calculating a maximum macroblock bit budget; tracking a totalbit usage for the current frame; tracking a count of a number ofprocessed macroblocks; and calculating the underflow quantizationparameter using the maximum macroblock bit budget, the total bit usage,and the count, wherein a new value of the underflow quantizationparameter is equal to a current value of underflow quantizationparameter multiplied by one plus the total bit usage minus a product ofthe count and the maximum macroblock bit budget divided by the maximummacroblock bit budget.
 8. The method of claim 7, further comprisingapplying activity masking to generate a macroblock quantizationparameter using the underflow quantization parameter.
 9. A method ofcreating macroblock quantization parameters for a current frame using aframe quantization parameter, the method comprising: setting an initialvalue of the macroblock quantization value to be equal to the framequantization parameter; calculating a maximum macroblock bit budget;tracking a total bit usage for the current frame; tracking a count of anumber of processed macroblocks; calculating the underflow quantizationparameter using the maximum macroblock bit budget, the total bit usage,and the count, wherein a new value of the underflow quantizationparameter is equal to a current value of underflow quantizationparameter multiplied by one plus the total bit usage minus a product ofthe count and the maximum macroblock bit budget divided by the maximummacroblock bit budget.
 10. The method of claim 9, further comprisingapplying activity masking to each macroblock.
 11. The method of claim 9,further comprising calculating the frame quantization parameter.
 12. Themethod of claim 11, wherein the calculating the frame quantizationparameter comprises: calculating a complexity ratio; calculating acurrent frame bit rate using the complexity ratio factor; andcalculating the frame quantization parameter based on the current framebit rate.
 13. A system for generating a frame quantization parameter forencoding a current frame of an incoming video stream having a pluralityof frames, the system comprising: means for calculating a complexityratio of the current frame; means for calculating a current frame bitrate, using the complexity ratio of the current frame; and means forcalculating the frame quantization parameter based on the current framebit rate; and wherein the means for calculating a complexity ratiocomprises: means for calculating a local complexity of the currentframe; means for calculating a global complexity of a plurality offrames; and means for setting the complexity ratio to equal the localcomplexity divided by the global complexity; and wherein the means forcalculating a local complexity comprises: means for calculating a newaverage local complexity; and means for calculating a new value for thelocal complexity as a weighted average of a current value of the localcomplexity and the new average local complexity.
 14. A system forgenerating a frame quantization parameter for encoding a current frameof an incoming video stream having a plurality of frames, the systemcomprising: means for calculating a complexity ratio of the currentframe; means for calculating a current frame bit rate using thecomplexity ratio of the current frame; means for calculating the framequantization parameter based on the current frame bit rate; and meansfor calculating a bit balance adjustment factor that is used by themeans for calculating a current frame bit rate using the complexityratio factor; wherein the means for calculating a bit balance adjustmentfactor comprises: means for tracking a bit balance of a plurality ofpreviously processed frames; means for dividing the bit balance by aduration to generate the bit balance adjustment factor.
 15. The systemof claim 13, further means for comprising calculating a frame codingefficiency factor.
 16. The system of claim 15, wherein the means forcalculating the frame quantization parameter based on the current framebit rate comprises: means for calculating a bit budget for the currentframe using the current frame bit rate; means for calculating an averagemacroblock quantization factor of a previous frame, wherein the previousframe and the current frame have a same frame type; means forcalculating the frame quantization parameter using the bit budget; theaverage macroblock quantization factor of the previous frame, and a bitusage of the previous frame.
 17. The system of claim 13, furthercomprising means for calculating an underflow quantization parameter foreach macroblock of the current frame.
 18. A system for creatingmacroblock quantization parameters for a current frame using a framequantization parameter, the system comprising: means for setting aninitial value of the macroblock quantization value to be equal to theframe quantization parameter; means for calculating a maximum macroblockbit budget; means for tracking a total bit usage for the current frame;means for tracking a count of a number of processed macroblocks; meansfor calculating the underflow quantization parameter using the maximummacroblock bit budget, the total bit usage, and the count; wherein a newvalue of the underflow quantization parameter is equal to a currentvalue of underflow quantization parameter multiplied by one plus thetotal bit usage minus a product of the count and the maximum macroblockbit budget divided by the maximum macroblock bit budget.
 19. The methodof claim 18, further comprising means for applying activity masking toeach macroblock.
 20. The system of claim 18, further comprising meansfor calculating the frame quantization parameter.
 21. The system ofclaim 20, wherein the means for calculating the frame quantizationparameter comprises: means for calculating a complexity ratio; means forcalculating a current frame bit rate using the complexity ratio factor;and means for calculating the frame quantization parameter based on thecurrent frame bit rate.